<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Admin\Controller;

/**
 * 后台用户控制器
 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
 */
class ContentController extends AdminController {
    public function banner(){
        $data=M('banner')->select();
        $this->assign('list',$data);
        //echo 111;
        $this->display();
    }
    public function ad_type(){
        $data=M('ad_type')->select();
        $this->assign('list',$data);
        //echo 111;
        $this->display();
    }
    //上传轮播图
    public function add_banner(){
        if(IS_POST){
            $data['icon']=I('post.icon');
            // $data['shop_id']=I('post.shop_id');
            $res=M('banner')->add($data);
            if($res){
                $this->success('添加成功',U('Content/banner'),1);die();
            }
        }
        $this->display();
    }
    public function ad_type_add(){
        if(IS_POST){
            $data['title']=I('post.title');
            // $data['shop_id']=I('post.shop_id');
            $res=M('ad_type')->add($data);
            if($res){
                $this->success('添加成功',U('Content/ad_type'),1);die();
            }
        }
        $this->display();
    }
    //修改轮播图
    public function edit_banner(){
        $id=I('get.id');
        //echo $id;
        $this->assign('id',$id);
        $list=M('banner')->where(array('id'=>$id))->find();
        $this->assign('info',$list);
        if(IS_POST){
            $img_id=I('post.id');
            $data['icon']=I('post.icon');
            //dump($id);die();
            $res=M('banner')->where(array('id'=>$img_id))->save($data);
            if($res){
                $this->success('修改成功',U('Content/banner'),1);die();
            }
        }
        $this->display();
    }
    public function foreverdelete(){
        $id=I('get.id');
        $data=M('banner')->where(array('id'=>$id))->delete();
        if($data){
            $this->success('操作成功',U('Content/banner'),1);die();
        }
    }
    public function ad_type_foreverdelete(){
        $id=I('get.id');
        $data=M('ad_type')->where(array('id'=>$id))->delete();
        if($data){
            $this->success('操作成功',U('Content/ad_type'),1);die();
        }
    }
    public function template(){
        $this->assign('list',M('template')->select());
        $this->display();
    }
    public function add_template(){
        $this->assign('ad_type',M('category')->where(array('pid'=>0))->select());
        if($_POST){
            $data['img']=I('post.icon');
            $data['title']=I('post.title');
            $data['type_id']=I('post.type_id');
            $data['ad_type']=I('post.ad_type');
            $res=M('template')->add($data);
            if($res){
                $this->success('操作成功',U('Content/template'),1);die();
            }
        }
        $this->display();
    }
    public function template_foreverdelete(){
        $id=I('get.id');
        $data=M('template')->where(array('id'=>$id))->delete();
        if($data){
            $this->success('操作成功',U('Content/template'),1);die();
        }
    }
    public function put_ad(){
        $list=M('shop_ad')->where(array('ad_type'=>2,'add_type'=>1))->select();
        $this->assign('list',$list);
        $this->display();
    }
    public function yin_ad(){
        $list=M('shop_ad')->where(array('ad_type'=>1,'add_type'=>1))->select();
        $this->assign('list',$list);
        $this->display();
    }
    public function confirm_put_ad(){
        $id=I('get.id');
        $data['status']=3;
        $res=M('shop_ad')->where(array('id'=>$id))->save($data);
        if($res){
            $this->success('操作成功',U('Content/put_ad'),1);die();
        }
    }
    public function shop_put_money(){
        $this->assign('list',M('shop_put_money')->select());
        $this->display();
    }
    public function confirm_put_money(){
        $id=I('get.id');
        $data['status']=2;
        $res=M('shop_put_money')->where(array('id'=>$id))->save($data);
        if($res){
            $this->success('操作成功',U('Content/shop_put_money'),1);die();
        }
    }
    public function cancel_put_money(){
        $id=I('get.id');
        $info=M('shop_put_money')->where(array('id'=>$id))->find();
        $shop_info=M('shop')->where(array('id'=>$info['shop_id']))->find();
        $balance['balance']=$shop_info['balance']+$info['money'];
        $balance['withdraw_balance']=$shop_info['withdraw_balance']+$info['money'];
        $balance['shop_balance']=$shop_info['shop_balance']+$info['money'];
        M('shop')->where(array('id'=>$info['shop_id']))->save($balance);
        $data['status']=3;
        $res=M('shop_put_money')->where(array('id'=>$id))->save($data);
        if($res){
            $this->success('操作成功',U('Content/shop_put_money'),1);die();
        }
    }
}
